package generalUsageTests.tests{
	import de.ghost23.common.statemachine.State;
	import de.ghost23.common.statemachine.StateMachine;

	import org.flexunit.Assert;

	import xmlStateMachine.XMLEvent;
	import xmlStateMachine.XMLStates;
	import xmlStateMachine.commands.ParseXML;
	import xmlStateMachine.commands.RequestFile;
	import xmlStateMachine.commands.Reset;
	import xmlStateMachine.commands.UnloadFile;

	public class BasicStateMachineTests extends StateMachine {

		// Possible state machine actions
		public static const LOAD:int	= 0x00000001;
		public static const PARSE:int	= 0x00000002;
		public static const UNLOAD:int	= 0x00000004;

		[Before]
		public function runBeforeEveryTest():void {
			
			targets[LOAD] = XMLStates.FILE_LOADED;
			targets[PARSE] = XMLStates.XML_PARSED;
			targets[UNLOAD] = XMLStates.EMPTY_IDLE;

			XMLStates.EMPTY_IDLE.inputCommand = Reset;
			XMLStates.EMPTY_IDLE.stateAfterEvent[XMLStates.FILE_REQUESTING] = XMLEvent.FILE_LOAD_REQUESTED;

			XMLStates.FILE_REQUESTING.inputCommand = RequestFile;
			XMLStates.FILE_REQUESTING.stateAfterEvent[XMLStates.FILE_LOADED] = XMLEvent.FILE_LOAD_COMPLETE;
			XMLStates.FILE_REQUESTING.stateAfterEvent[XMLStates.FILE_LOADERROR] = XMLEvent.FILE_LOAD_FAILED;

			XMLStates.FILE_LOADED.transient = true;
			XMLStates.FILE_LOADED.stateAfterEvent[XMLStates.XML_PARSING] = XMLEvent.XML_PARSING_STARTED;

			XMLStates.FILE_LOADERROR.transient = true;
			XMLStates.FILE_LOADERROR.stateAfterEvent[XMLStates.EMPTY_IDLE] = XMLEvent.MACHINE_RESET;

			XMLStates.XML_PARSING.inputCommand = ParseXML;
			XMLStates.XML_PARSING.stateAfterEvent[XMLStates.XML_PARSED] = XMLEvent.XML_PARSING_COMPLETE;
			XMLStates.XML_PARSING.stateAfterEvent[XMLStates.XML_REJECTED] = XMLEvent.XML_PARSING_FAILED;

			XMLStates.XML_PARSED.stateAfterEvent[XMLStates.FILE_UNLOADING] = XMLEvent.FILE_UNLOAD_REQUESTED;

			XMLStates.XML_REJECTED.transient = true;
			XMLStates.XML_REJECTED.stateAfterEvent[XMLStates.FILE_UNLOADING] = XMLEvent.FILE_UNLOAD_REQUESTED;

			XMLStates.FILE_UNLOADING.inputCommand = UnloadFile;
			XMLStates.FILE_UNLOADING.stateAfterEvent[XMLStates.EMPTY_IDLE] = XMLEvent.MACHINE_RESET;
		}

		[After]
		public function runAfterEveryTest():void {

		}

		[Test(description="Basic StateMachine tests!")]
		public function testDijkstra():void {

			var resultPathList:Vector.<State> = createTargetStatePath(currentState, XMLStates.XML_PARSED);
			for(var i:int = 0; i < resultPathList.length; i++) {
				trace("state: " + resultPathList[i].identifier);
			}

			Assert.assertTrue("resultPath is longer than 0", resultPathList.length);
		}

		// Definition of the state machine
		public function BasicStateMachineTests() {

			super(XMLStates.EMPTY_IDLE, XMLStates);
		}
	}
}